/**
 * 
 */
package org.jftstool.config;

import java.util.ArrayList;
import java.util.List;


/**
 * @author grupo JFTS
 *
 */
public class FileParserFrameworkConfig {
	private List<ExtensionConfig> extensions = null;
	private List<MimeTypeConfig> mimetypes = null;	
	
	public FileParserFrameworkConfig(){
		extensions = new ArrayList<ExtensionConfig>();
		mimetypes = new ArrayList<MimeTypeConfig>();		
	}
	
	public FileParserFrameworkConfig(List<ExtensionConfig> extensions, List<MimeTypeConfig> mimetypes){
		this.extensions = extensions;
		this.mimetypes = mimetypes;
	}

	public List<ExtensionConfig> getExtensions() {
		return extensions;
	}

	public void setExtensions(List<ExtensionConfig> extensions) {
		this.extensions = extensions;
	}

	public List<MimeTypeConfig> getMimetypes() {
		return mimetypes;
	}

	public void setMimetypes(List<MimeTypeConfig> mimetypes) {
		this.mimetypes = mimetypes;
	}
	
	public String getParserFromExtension(String extension){
		String result = null;
		for (ExtensionConfig a : extensions){
			String aux = a.getArg("extension").trim();			
			if (aux != null && aux.equalsIgnoreCase(extension)){
				result = a.getArg("class").trim();
			}
		}
		return result;
	}
	
	public String getParserFromMimeType(String mimeType){
		return getParserFromExtension(getExtensionFromMimeType(mimeType));
	}	
	
	public String getExtensionFromMimeType(String mimeType){
		String result = null;
		for(MimeTypeConfig a : mimetypes){
			String aux = a.getArg("mimeType").trim();
			if (aux != null &&  aux.equalsIgnoreCase(mimeType)){
				result = a.getArg("extension").trim();
			}
		}
		return result;
	}
}